#include <stdlib.h>
#include <math.h>

/*  Bresenham line-drawing procedure for |m| < 1.0.  */
void lineBres (int x0, int y0, int xEnd, int yEnd)
{
	int dx = fabs (xEnd - x0),  dy = fabs(yEnd - y0);
	int p = 2 * dy - dx;
	int twoDy = 2 * dy,  twoDyMinusDx = 2 * (dy - dx);
	int x, y;

	/* Determine which endpoint to use as start position.  */
	if (x0 > xEnd) 
	{
		x = xEnd;
		y = yEnd;
		xEnd = x0;
	}
	else 
	{
		x = x0;
		y = y0;
	}
	setPixel (x, y);

	while (x < xEnd) 
	{
		x++;
		if (p < 0)
			p += twoDy;
		else
		{
			y++;
			p += twoDyMinusDx;
		}
			setPixel (x, y);
	}
} 
